package com.kusiri.kframework.prana {

	import com.kusiri.kframework.KfContext;
	import com.kusiri.kframework.component.IKfComponent;
	
	import org.pranaframework.context.support.XMLApplicationContext;

	/**
	 * Extension of prana to allow KfComponents to know
	 * their creator.
	 */
	public class ApplicationContext extends XMLApplicationContext 
	{
		private var kfModule : KfContext;
		
		/**
		 * 
		 */
		public function ApplicationContext(kfModule : KfContext, source:*=null) {
			super(source);
			this.kfModule = kfModule;
		}
		
		/**
		 * 
		 */
		override public function getObject(name:String, constructorArguments:Array = null):*
		{
			var r:* = super.getObject(name, constructorArguments);
			if (r is IKfComponent) 
			{
				(r as IKfComponent).__generatorId = name;
				(r as IKfComponent).__context = kfModule;
			}
			return r;	
		}
	}
}